package com.zeng.springboot03web.dao;

import com.zeng.springboot03web.pojo.Department;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

// 被Spring 托管 才可以用 @Autowired
@Repository
public class DepartmentDao {
    // 初始化数据：模拟数据库中的数据

    // 在初始化时加载，需要static；库需要map实现
    private static Map<Integer, Department> departments = null ;

    // 下面赋初始值
    static {
        departments = new HashMap<>() ;  // 创建一个部门表，JDK1.8之后泛型可省略

        departments.put(1701, new Department(1701, "教学部")) ;
        departments.put(1702, new Department(1702, "市场部")) ;
        departments.put(1703, new Department(1703, "教研部")) ;
        departments.put(1704, new Department(1704, "运营部")) ;
        departments.put(1705, new Department(1705, "后勤部")) ;

    }

    /* 数据库的增删查改 */

    // 获得所有部门信息
    public Collection<Department> getDepartments() {
        return departments.values() ;
    }

    // 通过部门id得到部门信息
    public Department getDepartmentById(Integer id) {
        return departments.get(id) ;
    }
}
